@import "bootstrap";
@import "./pytch-mixins.scss";
@import "./pytch-variables.scss";

$drag-resizer-height: 0.5rem;
$tooltip-background-color: #151;

// It's possible there's a cleaner way to achieve this.  The value comes
// from 36px for the button height then 0.8px border top and bottom.
$stage-controls-height: 37.6px;

.abs-0000 {
  position: absolute;
  top: 0px;
  bottom: 0px;
  left: 0px;
  right: 0px;
}

.ProjectIDE {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0.5rem;
  display: flex;

  &.wide-info-pane {
    flex-direction: column;
  }
  &.tall-code-editor {
    flex-direction: row;
  }
  &.full-screen {
    margin: 0px;
  }

  .FullScreenStage {
    margin: auto;

    .run-stop-controls {
      display: flex;
      flex-direction: row;

      > * {
        margin-left: 16px;
      }

      > *:first-child {
        margin-left: 0px;
      }
    }
  }
}

.load-project-not-success {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;

  p {
    max-width: 36rem;
    font-size: 1.25rem;
    color: black;
    padding: 2rem;
    border-radius: 8px;
    margin-bottom: 3rem;
  }

  &.failed p {
    background-color: #faa;
  }

  &.pending p {
    background-color: #cfc;
  }
}

.StageWithControls {
  display: flex;
  flex-direction: column;
}

.tooltipped-elt {
  z-index: 1;
  .pytch-static-tooltip {
    &.hidden {
      display: none;
    }
    height: 0px;
    width: 0px;
    div.spacer {
      width: 0px;
      height: 0px;
      border-bottom: 18px solid $tooltip-background-color;
      border-left: 8px solid transparent;
      border-right: 8px solid transparent;
    }
    div.content {
      display: flex;
      flex-direction: row;
      align-items: center;
      background-color: $tooltip-background-color;
      padding: 1rem 1.5rem;
      border-radius: 0px 8px 8px 8px;
      color: white;
      width: 18rem;
      div.inner-content {
        margin-left: 1rem;
        p {
          margin: 0px;
        }
      }
    }
  }
}

.StageControls {
  display: flex;
  flex-direction: row;
  justify-content: space-between;

  > * {
    margin-left: 3px;
    margin-right: 3px;
  }

  > *:first-child {
    margin-left: 0px;
  }

  > *:last-child {
    margin-right: 0px;
  }

  .save-button {
    span {
      padding: 4px;
      border-radius: 4px;
    }
    &.unsaved-changes-exist span {
      background-color: yellow;
      color: black;
    }
  }
}

.stage-and-text-input {
  position: relative;
  .question-and-answer {
    padding: 6px;
    border: 1px solid #444;
    border-radius: 4px;
    background-color: #bbb;
    position: absolute;
    bottom: 0px;
    left: 0px;
    right: 0px;
    .prompt {
      margin: 0px 0px 0.25rem;
    }
    .input {
      position: relative;
      .font-container {
        position: absolute;
        right: 8px;
        top: 0px;
        bottom: 0px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        .check-icon {
          color: #007bff;
          &:hover {
            color: #0069d9;
          }
        }
      }
    }
  }
}

#pytch-stage-container {
  display: flex;
  flex-direction: row;
  justify-content: center;
}

#pytch-stage-layers {
  position: relative;
  margin-top: 0.5rem;
}

$canvas-border-width: 1px;

#pytch-canvas {
  border: $canvas-border-width solid grey;
  border-radius: 2px;
  background: white;
  display: block;
  visibility: visible;

  &.resize-active {
    visibility: hidden;
  }
}

#pytch-attribute-watchers,
#pytch-speech-bubbles {
  position: absolute;
  left: 0px;
  top: 0px;
  border: $canvas-border-width solid transparent;
  box-sizing: content-box;
  visibility: visible;

  &:focus {
    outline: none;
  }

  &.resize-active {
    visibility: hidden;
  }
}

.attribute-watcher {
  display: inline-block;
  position: absolute;
  border: 1px solid #88d;
  border-radius: 4px;
  background-color: #adf;
  padding: 4px;
  font-size: 13px;

  .label {
    display: inline-block;
    padding-left: 0rem;
    padding-right: 0.5rem;
    color: black;
  }

  .value {
    display: inline-block;
    border-radius: 6px;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    background-color: #007bff;
    color: white;
  }
}

#stage-resize-indicator {
  position: absolute;
  left: 0px;
  top: 0px;
  background-color: #888;
  border: 1px solid #444;
  box-sizing: content-box;
  visibility: hidden;

  &.resize-active {
    visibility: visible;
  }
}

$speech-bubble-background: #e8e8e8;
$speech-bubble-arrow: #ccc;
$speech-bubble-width: 210px;
$speech-bubble-max-height: 180px;

.speech-bubble {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: absolute;
  max-width: $speech-bubble-width;

  .content {
    background-color: $speech-bubble-background;
    padding: 4px;
    border: 2px solid $speech-bubble-arrow;
    border-radius: 4px;
    color: black;
    font-size: 14px;
    text-align: center;
    white-space: pre-wrap;
    max-width: 100%;
    max-height: $speech-bubble-max-height;
    overflow-y: hidden;
  }

  .arrow {
    width: 0px;
    height: 0px;
    border-top: 10px solid $speech-bubble-arrow;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
  }
}

/* This div appears at top level in the DOM even though it's logically
   part of the editor. */
.ace_editor.ace_autocomplete {
  width: 40rem;

  .ace_line {
    font-size: 90%;
    .ace_ {
      color: black;
    }
    .ace_completion-meta {
      color: #333;
      opacity: 1;
      font-style: italic;
      margin-left: 0.5em;
      margin-right: 0em;
    }
    .ace_completion-message {
      margin-left: 0.5rem;
    }
  }
}

.LinkedContentBar {
  background-color: $pytch-colour-main-blue;
  border-radius: 6px 6px 0px 0px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  p {
    margin: 0.25rem 0.5rem;
    font-size: 0.9rem;
    font-style: italic;
    color: #fff792;
  }
  button {
    padding: 0px 10px 0px 0px;
    margin-right: 8px;
    background-color: transparent;
    border-color: transparent;
    color: #fff792;
  }
}

.CodeEditor {
  flex-grow: 1;
  flex-shrink: 1;
  margin-right: 0.5rem;
  display: grid;
  grid-template-rows: auto 1fr;
  position: relative;
  z-index: 0;

  .editor-itself {
    display: flex;
    position: relative;
  }

  /* Override Ace's ordering of fonts to avoid Monaco-related
     mis-rendering in Safari.
     https://github.com/ajaxorg/ace/issues/3385
  */
  .ace_editor {
    font-family: $monospace-fonts;
  }

  .help-sidebar {
    display: flex;
    flex-direction: row;

    background-color: #e8e8e8;

    .content-wrapper {
      display: flex;
      &.hidden {
        display: none;
      }

      flex-direction: column;
      margin: 0px;

      .dismiss-help {
        border-color: transparent;
        p {
          margin: 0px;
          text-align: right;
        }
      }

      > .content {
        height: 1px; /* but will be grown by 'flex-grow' below */
        flex-grow: 1;
        flex-shrink: 1;
        overflow-y: scroll;
        margin: 0px;
      }
    }

    .control {
      flex-shrink: 0;
      @include background-color-as-button(
        $help-sidebar-expand-button-background
      );
      color: white;
      width: 1.5rem;
      @include align-center-middle();
      cursor: pointer;
      user-select: none;
    }
  }

  #editor {
    background-color: white;
    flex-grow: 1;
  }

  .ReadOnlyOverlay {
    z-index: 10;
    position: absolute;
    left: -4px;
    right: -4px;
    top: -4px;
    bottom: -4px;
    background-color: black;
    color: white;
    opacity: 0.4;
    display: flex;
    flex-direction: column;
    justify-content: space-around;

    p {
      opacity: 1;
      font-size: 2rem;
      text-align: center;
    }
  }
}

.CodeAndStage {
  display: flex;
  flex-direction: row;
}

.StageAndInfo {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.drag-resizer {
  height: $drag-resizer-height;
  flex-shrink: 0;

  &:hover {
    cursor: ns-resize;
    background-color: black;
    opacity: 0.2;
  }
}

.InfoPanel-container {
  position: relative;

  min-height: 0;
  flex-grow: 1;
  flex-shrink: 1;

  display: flex;
  flex-direction: column;

  .LayoutChooser {
    position: absolute;
    height: 32px;
    top: 0px;
    right: 0px;
    display: flex;
    flex-direction: row;
    button {
      height: 32px;
      margin-left: 0.5rem;
      display: flex;
      flex-direction: row;
      align-items: center;
    }
    .layout-icon {
      width: 24px;
    }
  }
}

div.spacer-instead-of-resizer {
  width: 100%;
  height: $drag-resizer-height;
  flex-shrink: 0;
}

.InfoPanel {
  min-height: 0;
  flex-grow: 0;
  flex-shrink: 0;
  margin-top: 0px;
  a {
    background-color: #eef;
  }
}

.InfoPanel + div {
  min-height: 0;
  flex-grow: 1;
  flex-shrink: 1;
  overflow-y: auto;
  background-color: white;
  position: relative;
}

.InfoPane {
  min-height: 0;
  flex-grow: 1;
  flex-shrink: 1;
}

.AssetCardPane,
.StandardOutputPane,
.EditorWebSocketInfo,
.ErrorsPane {
  flex-grow: 1;
  flex-shrink: 1;
  overflow-y: auto;

  p.info-pane-placeholder {
    font-size: 1.125rem;
    margin: 2rem 3rem 1rem 3rem;
  }
}

.StandardOutputPane,
.EditorWebSocketInfo {
  pre {
    margin: 2rem 3rem;
  }
}

.AssetCardPane {
  h1 {
    margin: 2rem;
  }

  .buttons {
    margin-left: 3rem;
    margin-bottom: 3rem;

    .assets-button {
      margin-right: 1rem;
      margin-left: 1rem;
    }
  }
}

.AssetCardList {
  margin: 1rem 0px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;

  .AssetCard {
    width: 20rem;
    margin: 1rem 3rem;
    background-color: #afa;

    .card-header {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;

      code {
        font-size: 1.25rem;
        color: black;
      }
    }

    .asset-preview {
      text-align: center;

      img {
        background-color: #bbb;
      }
    }

    .dropdown-item .with-icon {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
    }
  }
}

.ErrorReportPane {
  margin: 2rem 3rem;

  .ErrorReportAlert {
    code {
      color: #000;
      background-color: #eea;
      padding: 4px;
      border-radius: 4px;
    }

    blockquote {
      background-color: #700;
      padding: 0.5rem 1rem;
      border-radius: 4px;
      margin-left: 1rem;
      margin-right: 1rem;
      code {
        padding: 0px;
        background-color: inherit;
        color: white;
      }
    }

    li {
      margin: 0.75rem 0px;
    }

    .go-to-line {
      cursor: pointer;
      background-color: #007bff;
      color: white;
      padding: 6px;
      border-radius: 4px;

      &:hover {
        background-color: #0069d9;
      }
    }
  }
}

.StageControlPseudoButton {
  width: 4em;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;

  svg {
    color: white;
  }
}

.GreenFlag {
  background-color: #2c2;
  border: 1px solid #1a1;

  &:hover {
    background-color: #1a1;
  }
}

.RedStop {
  background-color: #e33;
  border: 1px solid #c11;

  &:hover {
    background-color: #c11;
  }
}

.modal-body .alert {
  margin-top: 1rem;
  p {
    margin: 0.5rem 1rem;
  }
}

.DisplayScreenshot .modal-content {
  img {
    display: block;
    margin: 1rem auto;
    border: 8px solid #ddd;
    border-radius: 4px;
  }
}

.DownloadZipfile {
  .icon-container {
    margin: 1rem 0;
    height: 5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
}

.CompoundTextInput {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  background-color: #ddd;
  padding: 0.25rem;
  border-radius: 6px;
  > * {
    margin-left: 0.25rem;
    margin-right: 0.25rem;
  }
  input {
    background-color: #eee;
    text-align: right;
    padding: 0.25rem;
  }
  .literal-fragment {
    font-weight: bold;
    white-space: nowrap;
  }
}

.add-assets {
  .body-container {
    position: relative;
    .spinner-container {
      display: flex;
      position: absolute;
      top: 0px;
      bottom: 0px;
      left: 0px;
      right: 0px;
      .spinner-border {
        margin: auto;
      }
    }
    .hidden {
      visibility: hidden;
    }
    .shown {
      visibility: shown;
    }
  }
}

.add-asset-failures {
  .modal-content {
    background-color: var(--bs-danger-bg-subtle);
    code {
      color: black;
    }
  }
}

.CropScaleImage {
  .modal-dialog {
    min-width: none;
    max-width: fit-content;

    .outer-content {
      display: flex;
      flex-direction: row;

      .left-content,
      .right-content {
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        h2 {
          font-size: 1.125rem;
          font-weight: normal;
        }
      }

      .left-content {
        /* Any way to share these constants with TypeScript code? */
        .crop-container {
          width: 400px;
          height: 270px;
          display: flex;
          flex-direction: row;
          justify-content: center;
          align-items: center;
        }
        .ReactCrop {
          max-width: 360px;
          max-height: 270px;
        }
      }

      .right-content {
        margin-left: 3rem;
        .buttons {
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          margin-top: 1.5rem;
          *:last-child {
            margin-left: 1.5em;
          }
        }
      }
    }
  }

  .StageMockup {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 0px;
    width: 360px;
    height: 270px;
    background-color: #eef;
    border: 1px solid grey;
    overflow: hidden;
  }

  .scale-range-container {
    display: flex;
    flex-direction: row;
    align-items: center;

    :first-child {
      margin-right: 1rem;
    }
    :last-child {
      margin-left: 1rem;
    }
  }
}

ul.ClipArtTagButtonCollection {
  list-style-type: none;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  padding: 0rem;
  margin: 0rem;

  button {
    margin: 0.25rem;
    font-size: 0.875rem;
    padding: 3px 6px;
  }
}

.clipart-gallery {
  overflow-y: scroll;
  max-height: 30rem;
  ul {
    list-style-type: none;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-evenly;
    padding: 0rem;
  }
  li {
    background-color: #eee;
    border-color: #eee;
    border-width: 8px;
    border-radius: 4px;
    border-style: solid;
    margin: 0.5rem;
    cursor: pointer;
    p {
      margin: 0rem;
    }
  }
}

.clipart-body .modal-separator {
  margin: 0.5rem 0px 0.75rem;
  border-bottom: 1px solid $border-color;
}

.modal-footer.clipart-footer {
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;

  .licence-info p {
    margin: 0px;
    font-style: italic;
  }

  .buttons {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    justify-content: flex-end;

    button {
      margin-left: 1rem;
    }
  }
}

.clipart-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;

  .decorations {
    display: flex;
    flex-direction: row;
    justify-content: space-between;

    .n-items-label {
      display: inline-block;
      font-size: 0.8rem;
      background-color: $primary;
      color: white;
      padding: 2px 4px;
      border-radius: 4px;
    }
  }

  .clipart-name {
    text-align: left;
    font-weight: bold;
  }

  .clipart-thumbnail {
    text-align: center;
    margin: 0.5rem;
  }

  .clipart-selection.selected {
    color: rgb(0, 0, 255);
  }
  .clipart-selection.unselected {
    color: #c8c8c8;
  }
}
.clipart-card:hover {
  .clipart-selection.unselected {
    color: mix(blue, #c8c8c8, 40%);
  }
}

.CoordinateChooserBar {
  height: $stage-controls-height;
  display: flex;
  flex-direction: row;
  background-color: #888;
  border-radius: 4px;
  color: white;
  justify-content: space-between;
  align-items: center;

  .CoordsChooserBarMessage {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    > div {
      grid-area: 1 / 1 / 2 / 2;
    }
  }

  .CoordinateChooserBarContents {
    display: grid;
    grid-template-columns: auto 1fr;
  }

  .coords {
    code {
      display: inline-block;
      font-size: 90%;
      transform-origin: 0% 0%;
      transform: translateY(-0.0667rem) scaleX(0.8888);
      color: white;
      .label {
        color: #ddd;
      }
    }
    white-space: pre;
    margin-left: 1rem;
    &.spacer {
      visibility: hidden;
    }
  }
  .info {
    font-style: italic;
    color: #eee;
    visibility: hidden;
    &.isActive {
      visibility: visible;
    }
    &.copied {
      color: #8f8;
    }
    &.bare-message {
      margin-left: 1rem;
    }
  }
  .close-button {
    background-color: #888;
    border: none;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0px 12px;
    font-size: 1.333rem;
    margin-right: 0.333rem;
  }
}

.CoordinateChooserSubOverlay {
  background-color: #222;
  opacity: 0.4;
  border: $canvas-border-width solid transparent;
}

.CoordinateChooserOverlay {
  cursor: crosshair;
  color: white;
  border: $canvas-border-width solid transparent;
  .grid {
    width: 100%;
    height: 100%;

    .h-centre {
      display: flex;
      flex-direction: row;
      justify-content: center;
    }
    .v-centre {
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    .h-split {
      display: grid;
      grid-template-columns: 1fr 1fr;
    }
    .v-split {
      display: grid;
      grid-template-rows: 1fr 1fr;
    }

    .x-axis {
      width: calc(100% - 5px);
      height: 2px;
      background-color: white;
    }
    .y-axis {
      align-self: self-end;
      height: calc(100% - 5px);
      width: 2px;
      background-color: white;
    }

    * > .origin {
      align-self: center;
      width: 8px;
      height: 8px;
      background-color: white;
      border-radius: 50%;
    }

    * > .arrow {
      width: 10px;
      height: 10px;
      background-color: white;
    }
    .v-centre > .arrow {
      align-self: end;
      clip-path: polygon(0% 0%, 100% 50%, 0% 100%);
    }
    .h-centre > .arrow {
      clip-path: polygon(0% 100%, 50% 0%, 100% 100%);
    }

    .x-ticks > div > div {
      padding: 0.25rem;
    }

    .y-ticks > div > div {
      padding: 0px 0.5rem;
    }
  }
}

#pytch-ace-editor {
  > .ace_gutter {
    padding-top: 0.25rem;
  }
  > .ace_scroller {
    padding-top: 0.25rem;
  }
}

.ViewCodeDiffModal {
  .table-container {
    width: 100%;
    max-height: 70vh;
    overflow: auto;
  }

  table.code-diff.side-by-side {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;

    th {
      width: 50%;
      &:nth-child(2) {
        width: 1rem;
      }
      text-align: center;
      padding: 1rem;
    }
    td {
      padding: 0px;
    }

    td:nth-child(2) {
      background-color: transparent;
    }

    tbody.diff-hunk.add {
      td:nth-child(1) {
        background-color: #eee;
      }
      td:nth-child(3) {
        background-color: #dfd;
      }
    }
    tbody.diff-hunk.del {
      td:nth-child(1) {
        background-color: #fdd;
      }
      td:nth-child(3) {
        background-color: #eee;
      }
    }
    tbody.diff-hunk.change {
      td:nth-child(1) {
        background-color: #fdd;
      }
      td:nth-child(3) {
        background-color: #dfd;
      }
    }
    tbody.diff-hunk.context {
      td {
        background-color: #fff;
      }
    }
    tr td pre {
      min-height: 1ex;
      margin: 2px;
      padding-left: 0.5rem;
      padding-right: 0.5rem;
    }
  }
}
